<extend name="Base/base" />

<block name="main">
    <!-- Content Header (Page header) -->
        <section class="content-header">
          <h1>
            地址管理
            <small>preview of simple tables</small>
          </h1>
          <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li><a href="#">地址信息</a></li>
            <li class="active">列表</li>
          </ol>
        </section>
        
        <!-- Main content -->
        <section class="content">
         
          <div class="row">
            <div class="col-md-12">
              <div class="box">
                <div class="box-header with-border">
                  <h3 class="box-title"><i class="fa fa-th"></i> 地址信息管理</h3>
                </div><!-- /.box-header -->
                <div class="box-body">
                  <form  class="form-inline" action="__URL__/index" method="get">
                    <div class="form-group">
                        <label class="sr-only" for="username">username</label>
                        <input type="input" class="form-control" name="username" placeholder="按用户名查找">
                    </div>
                     <div class="form-group">
                        <label class="sr-only" for="username">name</label>
                        <input type="input" class="form-control" name="name" placeholder="按收货人查找">
                    </div>
                    <label class="sr-only"  for="sex">性别</label>
                    <select class="form-control" name="sex">
                      <option value="">--请选择性别--</option>
                      <option value="0">女</option>
                      <option value="1">男</option>
                    </select>
                    <button type="submit" class="btn btn-default"><i class="glyphicon glyphicon-search"></i></button>
                  </form><br>

                  <table class="table table-bordered">
                    <thead>
                    <tr>
                      <th style="width:60px">ID</th>
                      <th>用户名</th>
                      <th>收货人</th>
                      <th>性别</th>
                      <th>地址</th>
                      <th>手机号</th>
                      <th>状态</th>
                      <th>添加时间</th>
                      <th style="width:200px">操作</th>
                    </tr>
                    </thead>
                  <tbody>
                   <volist name="list" id="vo">
                    <tr>
                      <td> {$vo.id} </td>
                      <td>{$vo.username}</td>
                      <td>{$vo.name}</td>
                      <td><if condition="($vo.sex eq 1) ">男<elseif condition="($vo.sex heq '0') "/>女</if></td>
                      <td><if condition="($vo.address eq 1) ">小店区<elseif condition="($vo.address eq 2)"/>迎泽区<elseif condition="($vo.address eq 3)"/>杏花岭区<elseif condition="($vo.address eq 4)"/>尖草坪区<elseif condition="($vo.address eq 5)"/>万柏林区<elseif condition="($vo.address eq 6)"/>晋源区</if>{$vo.detail_add} </td>
                      <td>{$vo.phone}</td>
                      <td id="state{$vo.id}"><if condition="($vo.state eq 1) ">普通<elseif condition="($vo.state heq '0') "/>默认</if></td>
                      <td>{$vo.addtime|date="Y-m-d",###}</td>
                      <td >
                      <button class="btn btn-xs btn-primary" onclick="doEdit({$vo.id})">编辑</button> 
                      <span id="btn{$vo.id}"><button class="btn btn-xs btn-warning" onclick="doMo({$vo.id},{$vo.state})"  ><if condition="($vo.state eq 1) ">设为默认<elseif condition="($vo.state heq '0') "/>取消默认</if></button>
                      </span>  </td>
                    </tr>
                    </volist>
                   </tbody>
                  </table>
                </div><!-- /.box-body -->
                <div class="box-footer clearfix">
                    {$page}
                  <!-- </ul> -->
                </div>
              </div><!-- /.box -->

              
              
            </div><!-- /.col -->
            
          </div><!-- /.row -->
         
        </section><!-- /.content -->
        
</block>
<block name="myscript">

  <script type="text/javascript">

       function doDel(obj,id){
            Modal.confirm({msg:'确定要删除当前标签吗？'}).on(function(e){
                if (e) {
                    $.ajax({
                      type:"get",
                      url:"__URL__/del",
                      data:"id="+id,
                      dataType:"json",
                      success:function (data){
                        if(data.b){
                          $(obj).parents("tr").remove();
                        }
                      },
                      error:function () {
                          
                      }
                    });
                }
            })
        }
      function doEdit(id) {
          window.location.href="__CONTROLLER__/edit/id/"+id;
      }
      function doMo(id,state){
          $.ajax({
            type:"get",
            url:"__URL__/mo",
            data:"id="+id+"&state="+state,
            dataType:"json",
            success:function (data){
              if(data.b){
                if (data.a===1) {
                  $("#state"+data.id).html("普通");
                  $("#btn"+data.id).html("<button class='btn btn-xs btn-warning' onclick='doMo("+data.id+","+data.a+")' >设为默认</button>");
                }else{
                  
                  $("#state"+data.id).html("默认");
                  $("#btn"+data.id).html("<button class='btn btn-xs btn-warning' onclick='doMo("+data.id+","+data.a+")' >取消默认</button>");
                }
              }
            },
            error:function () {
                
            }
          });
      }
  </script>
  
</block>